package com.huatai.common.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * @program: ht-system
 * @description: mybatis创建时间更新时间自动加入
 * @author: songxiude
 * @create: 2023-02-03 15:51
 **/
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
	public void insertFill(MetaObject metaObject) {
		this.strictInsertFill(metaObject, "createTime", LocalDateTime.class, LocalDateTime.now());
		this.strictUpdateFill(metaObject, "updateTime", LocalDateTime.class, LocalDateTime.now()); // 起始版本 3.3.0(推荐使用)
	}

	@Override
	public void updateFill(MetaObject metaObject) {
		//this.strictUpdateFill(metaObject, "updateTime", LocalDateTime.class, LocalDateTime.now()); // 起始版本 3.3.0(推荐使用)
		this.setFieldValByName("updateTime", LocalDateTime.now(),metaObject);
	}
}
